import { ApiProperty } from "@nestjs/swagger";
import { CrudValidationGroups } from "@nestjsx/crud";
import { IsString } from "class-validator";
import { Column, Entity, OneToMany, PrimaryGeneratedColumn } from "typeorm";
import { BaseEntity } from "./base.entity";
import { Town } from "./town.entity";
import { User } from "./user.entity";

const { CREATE, UPDATE } = CrudValidationGroups;

@Entity()
export class Area extends BaseEntity {
  @ApiProperty({
    description: '主键',
    required: false,
  })
  @PrimaryGeneratedColumn()
  id: number;

  @ApiProperty({
    example: '区名称',
    description: '区，名称',
  })
  @IsString({ always: true })
  @Column({
    type: "char",
    length: 255,
  })
  name : string;

  @ApiProperty({
    type: String,
    example: '镇id,镇id 或者 town []',
    description: '镇',
    required: false,
  })
  @OneToMany(() => Town, Town => Town.area)
  town ?: string | Town []

  @ApiProperty({
    example: 1,
    description: '区级管理员',
    required: false,
    type: Number
  })
  @OneToMany(() => User, User => User.area)
  users ?: User []
}